<template>
  <!--顶部导航栏 start-->
  <ExamMenu />
  <!--顶部导航栏 end-->
  <div class="auth-container">
    <!-- 动态背景 -->
    <div class="animated-bg"></div>

    <!-- 主体内容容器 -->
    <div class="content-wrapper">
      <!-- 左侧插画 -->
      <div class="illustration-container">
        <transition name="illustration-fade" appear>
          <div class="illustration-content">
            <img src="@/assets/drone.svg" alt="认证流程插画" class="illustration-img" />
          </div>
        </transition>

      </div>

      <!-- 右侧表单 -->
      <transition name="form-fade" appear @before-enter="beforeFormEnter" @after-enter="formEntered">
        <div class="form-wrapper">
          <!-- 切换按钮 -->
          <div class="mode-switch">
            <button v-for="tab in tabs" :key="tab" :class="{ active: activeTab === tab }" @click="switchTab(tab)">
              {{ tab === 'login' ? '登录' : '注册' }}
            </button>
          </div>

          <!-- 表单区域 -->
          <transition :name="transitionDirection" mode="out-in">
            <component :is="activeTab === 'login' ? LoginForm : RegisterForm" class="form-component" :key="activeTab" />
          </transition>
        </div>
      </transition>
    </div>
  </div>
  <!--底部 start-->
  <ExamFooter />
  <!--底部 end-->
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import LoginForm from '@/components/login/LoginForm.vue'
import RegisterForm from '@/components/login/RegisterForm.vue'
import ExamFooter from '@/components/comm/ExamFooter.vue';
import ExamMenu from '@/components/comm/ExamMenu.vue';
const activeTab = ref<'login' | 'register'>('login')
const tabs = ['login', 'register'] as const
const lastTab = ref<'login' | 'register'>('login')

const transitionDirection = computed(() => {
  return lastTab.value === 'login' ? 'slide-left' : 'slide-right'
})

const switchTab = (tab: 'login' | 'register') => {
  lastTab.value = activeTab.value
  activeTab.value = tab
}

const beforeFormEnter = (el: Element) => {
  const element = el as HTMLElement
  element.style.opacity = '0'
  element.style.transform = 'translateX(30px)'
}

const formEntered = (el: Element) => {
  const element = el as HTMLElement
  element.style.transition = 'all 0.4s cubic-bezier(0.4, 0, 0.2, 1)'
  element.style.opacity = '1'
  element.style.transform = 'translateX(0)'
}
</script>

<style lang="scss" scoped>
.auth-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  background: #f5f7fa;

  .animated-bg {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg,
        #3B82F6,
        #6366F1,
        #8B5CF6);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    filter: blur(40px);
    opacity: 0.4;
    z-index: 0;
  }

  .content-wrapper {
    position: relative;
    z-index: 1;
    display: flex;
    width: 82%;
    max-width: 1200px;
    height: 75vh;
    min-height: 600px;
    background: white;
    border-radius: 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
    overflow: hidden;
  }

  .illustration-container {
    max-width: 58%;
    flex: 1;
    padding: 40px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;

    .illustration-content {
      max-width: 600px;
      width: 100%;
      padding: 20px;
      transition: opacity 0.5s ease;

      .illustration-img {
        width: 100%;
        height: auto;
        object-fit: contain;
        filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.1));
      }
    }
  }

  .form-wrapper {
    flex: 0 0 38%;
    padding: 60px 40px;
    display: flex;
    flex-direction: column;
    background: white;

    .mode-switch {
      display: flex;
      margin-bottom: 40px;
      border-radius: 12px;
      background: #f3f4f6;
      padding: 6px;
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.04);

      button {
        flex: 1;
        padding: 14px;
        border: none;
        background: none;
        font-size: 16px;
        font-weight: 500;
        color: #6b7280;
        cursor: pointer;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 8px;
        position: relative;

        &.active {
          background: white;
          color: #3b82f6;
          box-shadow: 0 2px 8px rgba(59, 130, 246, 0.12);
          transform: translateY(-1px);
        }

        &:hover:not(.active) {
          color: #3b82f6;
        }
      }
    }
  }
}

/* 动画相关样式 */
@keyframes gradientBG {
  0% {
    background-position: 0% 50%
  }

  50% {
    background-position: 100% 50%
  }

  100% {
    background-position: 0% 50%
  }
}

.illustration-fade-enter-active,
.illustration-fade-leave-active {
  transition: opacity 0.8s ease;
}

.illustration-fade-enter-from,
.illustration-fade-leave-to {
  opacity: 0;
}

.form-fade-enter-active {
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-fade-enter-from {
  opacity: 0;
  transform: translateX(30px);
}

.slide-left-enter-active,
.slide-left-leave-active,
.slide-right-enter-active,
.slide-right-leave-active {
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-left-enter-from {
  opacity: 0;
  transform: translateX(40px);
}

.slide-left-leave-to {
  opacity: 0;
  transform: translateX(-40px);
}

.slide-right-enter-from {
  opacity: 0;
  transform: translateX(-40px);
}

.slide-right-leave-to {
  opacity: 0;
  transform: translateX(40px);
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .auth-container {
    .content-wrapper {
      width: 90%;
      height: auto;
      min-height: auto;
      margin: 40px 0;
    }

    .illustration-container {
      padding: 30px;
    }

    .form-wrapper {
      padding: 40px 30px;
    }
  }
}

@media (max-width: 768px) {
  .auth-container {
    height: auto;
    min-height: 100vh;
    padding: 20px;

    .content-wrapper {
      flex-direction: column;
      width: 100% !important;
      height: auto;
    }

    .illustration-container {
      flex: none;
      height: 240px;
      padding: 20px;

      .illustration-content {
        max-width: 280px;
      }
    }

    .form-wrapper {
      flex: none;
      padding: 40px 25px;
    }
  }
}

@media (max-width: 480px) {
  .auth-container {
    .form-wrapper {
      padding: 30px 20px;

      .mode-switch {
        margin-bottom: 30px;

        button {
          font-size: 15px;
          padding: 12px;
        }
      }
    }
  }
}


.drone {
  animation: float 15s cubic-bezier(0.54, 1.35, 1, 1) infinite;
}</style>